package com.learn.captcha;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.learn.result.Result;
import com.learn.result.ResultUtils;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import lombok.extern.slf4j.Slf4j;
//https://blog.csdn.net/Woo_home/article/details/108512215
//https://blog.csdn.net/qq_58159506/article/details/141502083
@Slf4j
@RestController
public class CaptchaController {
    @RequestMapping("/captcha")
    public Result<String> getCaptcha() {
        try {
            // 定义图形验证码的长、宽、验证码字符数、干扰元素个数
            CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(200, 100, 4, 20);
            // 输出到页面
            String imageBase64Data = captcha.getImageBase64Data();
            return ResultUtils.success(imageBase64Data,"success");
        } catch (Exception e) {
            throw new RuntimeException("生成验证码失败", e);
        }
    }
}
